package com.deyuanyun.pic.settings.service.pipe.impl;

import com.deyuanyun.pic.common.cache.TempStoreDataSupport;
import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.settings.domain.pipe.PipeLineElement;
import com.deyuanyun.pic.settings.mapper.pipe.PipeLineElementMapper;
import com.deyuanyun.pic.settings.service.pipe.PipeLineElementService;
import com.deyuanyun.pic.settings.support.utils.PipeDictUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 *  管道组成元素service
 *  @author axiao(xj08.dream@gmail.com)
 *  @date 2016-08-31
 *  @version 1.0
 *  Histroy: [修改人][时间][描述]
 */
@Service("PipeLineElementSettingService")
public class PipeLineElementServiceImpl implements PipeLineElementService {

    @Resource(name = "PipeLineElementSettingMapper")
    private PipeLineElementMapper pipeLineElementMapper;

    @Override
    public String findFromToValveRoom(String pipeLineId, String type) {
        return pipeLineElementMapper.findFromToValveRoom(pipeLineId, type);
    }


    @Override
    public List<PipeLineElement> queryElementsById(String pipeLineId, String type) {
        return pipeLineElementMapper.queryElementsById(pipeLineId, type);
    }

    /**
     * 清空管道缓存
     * @param
     * @return
     * @author axiao(xj08.dream@gmail.com)
     * @date 2016-11-18
     */
    private void clearPipeLineCache() {
        TempStoreDataSupport.removeData(PipeDictUtils.PIPEDICTUTILS_PIPELINEBIMAP);
        TempStoreDataSupport.removeData(PipeDictUtils.PIPEDICTUTILS_PIPELINEMAP);
        TempStoreDataSupport.removeData("pic_pipeLineList_"); //todo 坑
    }

    @Override
    public int updateElements(String id, String status, BigDecimal mileage) {
        int n = pipeLineElementMapper.updateElementSegmentation(id, status, mileage);
        if(n > 0) {
            clearPipeLineCache();
        }
        return n;
    }
}
